package 二叉树遍历;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    static boolean[] st = new boolean[30];
    static StringBuilder res = new StringBuilder("");

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String inorder = in.next();
        String lorder = in.next();
        Node[] q = new Node[30];
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < inorder.length(); i++) {
            map.put(inorder.charAt(i), i);
        }
        q[0] = new Node(lorder.charAt(0));
        for (int i = 0, j = 1; i < j && j < lorder.length(); i++) {
            int pos = map.get(lorder.charAt(i));
            st[pos] = true;
            if (pos > 0 && !st[pos - 1]) {
                q[i].left = new Node(lorder.charAt(j));
                q[j++] = q[i].left;
            }
            if (pos < lorder.length() - 1 && !st[pos + 1]) {
                q[i].right = new Node(lorder.charAt(j));
                q[j++] = q[i].right;
            }
        }
        dfs(q[0]);
        System.out.println(res.toString());
    }

    private static void dfs(Node root) {
        if (root == null) {
            return;
        }
        res.append(root.val);
        dfs(root.left);
        dfs(root.right);
    }
}

class Node {
    public char val;
    public Node left;
    public Node right;

    public Node(char val) {
        this.val = val;
    }
}
